﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WcfClient.ServiceReferenceHttp;

namespace WcfClient
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // WCF wsHttp链接(会话服务)  发送字符串请求.
            ServiceReferenceHttp.WCFServiceClient wcfServiceProxyHttp = new WCFServiceClient("WSHttpBinding_IWCFService1");
            string receiveMsg = wcfServiceProxyHttp.SayHello("RaoGs");
            MessageBox.Show(receiveMsg);
            wcfServiceProxyHttp.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //WCF wsHttp链接(会话服务) 发送对象
            ServiceReferenceHttp.WCFServiceClient wcfServiceProxyHttp = new WCFServiceClient("WSHttpBinding_IWCFService1");
            ServiceReferenceHttp.User user = new User() { FirstName = "Rao", LastName = "gang shan" };
            MessageBox.Show(wcfServiceProxyHttp.SayHelloToUser(user));
            wcfServiceProxyHttp.Close();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            //WCF netTcp链接(会话服务) 发送字符串请求,返回字符串
            ServiceReferenceTcp.WCFServiceClient wcfServiceProxyTcp = new WcfClient.ServiceReferenceTcp.WCFServiceClient("NetTcpBinding_IWCFService");
            string receiveMsg = wcfServiceProxyTcp.SayHello("RaoGs");
            MessageBox.Show(receiveMsg);
            wcfServiceProxyTcp.Close();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            //WCF netTcp链接(会话服务) 发送对象请求,返回字符串
            ServiceReferenceTcp.WCFServiceClient wcfServiceProxyTcp = new ServiceReferenceTcp.WCFServiceClient("NetTcpBinding_IWCFService");
            ServiceReferenceTcp.User user = new WcfClient.ServiceReferenceTcp.User() { FirstName = "Rao", LastName = "gang shan" };
            MessageBox.Show(wcfServiceProxyTcp.SayHelloToUser(user));
            wcfServiceProxyTcp.Close();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            // Service方法重载,并重命名方法
            ServiceReferenceOverLoadHttp.WCFOverLoadingServiceClient wcfServiceProxyHttp = new WcfClient.ServiceReferenceOverLoadHttp.WCFOverLoadingServiceClient("WSHttpBinding_WCFOverLoadingService");
            string receiveMsg = wcfServiceProxyHttp.SayHelloOverLoading1();
            MessageBox.Show(receiveMsg);
            wcfServiceProxyHttp.Close();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            // 单例服务
            OperateUserHttp.OperateUseAccountClient wcfOperateProxyHttp = new WcfClient.OperateUserHttp.OperateUseAccountClient("WSHttpBinding_IOperateUseAccount");
            IList<OperateUserHttp.UserAccount> lists = new List<OperateUserHttp.UserAccount>();
            lists.Add(new WcfClient.OperateUserHttp.UserAccount() { UserName = "rao", LoginIP = "190.160.9.10", LoginData = DateTime.Now.ToString() });
            lists.Add(new WcfClient.OperateUserHttp.UserAccount() { UserName = "gang", LoginIP = "190.160.9.11", LoginData = DateTime.Now.ToString() });
            lists.Add(new WcfClient.OperateUserHttp.UserAccount() { UserName = "shan", LoginIP = "190.160.9.12", LoginData = DateTime.Now.ToString() });
            wcfOperateProxyHttp.Insert(lists.ToArray());
            wcfOperateProxyHttp.Close();
        }

        private void WcfOperateHttp_Select_Click(object sender, EventArgs e)
        {
            OperateUserHttp.OperateUseAccountClient wcfOperateProxyHttp = new WcfClient.OperateUserHttp.OperateUseAccountClient("WSHttpBinding_IOperateUseAccount");
            IList<OperateUserHttp.UserAccount> lists = wcfOperateProxyHttp.Select();
            foreach (OperateUserHttp.UserAccount item in lists)
            {
                MessageBox.Show(string.Format(System.Environment.NewLine + "UserName={0}-LoginIP={1}-LoginData={2} ", item.UserName, item.LoginIP, item.LoginData));
            }
            wcfOperateProxyHttp.Close();
        }

        private void button7_Click(object sender, EventArgs e)
        {
            // 回调函数
            WCFServiceHttpCallBack.IWCFServiceCBCallback callback = new WCFServiceHttpCallBack.WCFServiceCBCallback();
            System.ServiceModel.InstanceContext m_InstanceContext = new System.ServiceModel.InstanceContext(callback);
            WCFServiceHttpCallBack.WCFServiceCBClient wcfServiceProxy = new WcfClient.WCFServiceHttpCallBack.WCFServiceCBClient(m_InstanceContext, "NetTcpBinding_IWCFServiceCB");
            MessageBox.Show(wcfServiceProxy.SayHelloToUser("Rao gang shan "));
        }
    }
}
